package com.niubi.yygh.task.tip;

import com.niubi.yygh.rabbit.RabbitService;
import com.niubi.yygh.rabbit.constant.MqConst;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@EnableScheduling
public class ScheduledTask {

    @Autowired
    private RabbitService rabbitService;

    /**
     * 每天8点执行 提醒就诊
     */
    //每天晚上八点执行，查询第二天有哪些人需要看病，给这些人分别发送短信
    //@Scheduled(cron ="0 0 20 * * ?")
    @Scheduled(cron = "0/10 * * * * ?")  //每5秒执行
    public void task1() {
        System.out.println(new Date().toLocaleString());
        //在每天晚上八点，查询第二天数据
        //在每天晚上八点，获取第二天日期
        DateTime dateTime = new DateTime().plusDays(1);
        String dateString = dateTime.toString("yyyy-MM-dd");
        //mq消息
        rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_TASK,
                MqConst.ROUTING_TASK_8,
                dateString);
    }
}